package com.campus.shop.service.impl;

import com.campus.shop.entity.GoodsCategory;
import com.campus.shop.mapper.GoodsCategoryMapper;
import com.campus.shop.service.GoodsCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.campus.shop.common.ConstantProperties;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 商品分类表 服务实现类11212
 * </p>
 *
 * @author xr
 * @since 2023-12-360 14:31:19
 */
@Service
public class GoodsCategoryServiceImpl extends ServiceImpl<GoodsCategoryMapper, GoodsCategory> implements GoodsCategoryService {
    @Autowired
    private GoodsCategoryMapper GoodsCategoryMapper;

    @Override
    public Boolean insertGoodsCategory(GoodsCategory goodsCategory) {
        return this.save(goodsCategory);
    }

    @Override
    public Boolean updateGoodsCategory(GoodsCategory goodsCategory) {
        return this.updateById(goodsCategory);
    }

    @Override
    public Boolean deleteGoodsCategory(Long id) {
        return this.removeById(id);
    }

    @Override
    public GoodsCategory queryById(Long id) {
        return this.getById(id);
    }

    @Override
    public HashMap<String, Object> pageList(Integer currentPage) {
        QueryWrapper<GoodsCategory> queryWrapper = new QueryWrapper<>();
        Page<GoodsCategory> GoodsCategorypage = new Page<>(currentPage, ConstantProperties.goods_limit);
        Page<GoodsCategory> page = GoodsCategoryMapper.selectPage(GoodsCategorypage, queryWrapper);
        List<GoodsCategory> list = page.getRecords(); //当前页数数据
        long total = page.getTotal(); //总条数
        HashMap<String, Object> res = new HashMap<>();
        res.put("total", total);
        res.put("list", list);
        return res;
    }
}

